package cn.tm.ms.nerver.neural.entry;

/**
 * 模块配置
 * 
 * @author lry
 */
public class NeuralConf {

	/**
	 * 默认放通率
	 */
	public static final double DEFAULT_PASSRATE=1.0;
	/**
	 * 默认的最大重试次数
	 */
	public static final int DEFAULT_MAXRETRYNUM=0;
	/**
	 * 默认重试休眠周期,默认不休眠
	 */
	public static final long DEFAULT_RETRYCYCLE=0;
	/**
	 * 默认Mock服务开关
	 */
	public static final boolean DEFAULT_MOCK_ENABLE=false;
	/**
	 * 默认容错失败后是否抛异常开关
	 */
	public static final boolean DEFAULT_FALLBACKFE_ENABLE=true;
	/**
	 * 默认失败通知开关
	 */
	public static final boolean DEFAULT_FAILNOTIFY_ENABLE=true;
	
	private double passRate=DEFAULT_PASSRATE;//放通率:用于控制后端服务放通的概率,默认1.0表示100%放通,即不做限制
	private int maxRetryNum=DEFAULT_MAXRETRYNUM;//最大重试次数
	private long retryCycle=DEFAULT_RETRYCYCLE;//重试休眠周期,默认不休眠
	
	private boolean mockEnable=DEFAULT_MOCK_ENABLE;//mock服务开关
	private boolean fallbackFEEnable=DEFAULT_FALLBACKFE_ENABLE;//所有容错失败后是否抛异常开关
	private boolean failNotifyEnable=DEFAULT_FAILNOTIFY_ENABLE;//失败通知开关
	
	public NeuralConf() {
	}
	
	/**
	 * @param maxRetryNum 最大重试次数,默认为3次
	 * @param retryCycle 重试休眠周期,默认休眠10ms(强烈不建议设置为0,因为释放句柄资源需要一定的时间)
	 * @param mockEnable mock服务开关,默认为false(关闭)
	 */
	public NeuralConf(int maxRetryNum, long retryCycle, boolean mockEnable){
		this.maxRetryNum=maxRetryNum;
		this.retryCycle=retryCycle;
		this.mockEnable=mockEnable;
	}
	
	
	/**
	 * @param passRate 放通率,默认为1.0(即100%的放通)
	 * @param maxRetryNum 最大重试次数,默认为3次
	 * @param retryCycle 重试休眠周期,默认休眠10ms(强烈不建议设置为0,因为释放句柄资源需要一定的时间)
	 * @param fallbackFEEnable 容错失败是否抛异常开关,默认为true(开启)
	 * @param mockEnable mock服务开关,默认为false(关闭)
	 * @param failNotifyEnable 失败通知开关,默认为开启
	 */
	public NeuralConf(double passRate, int maxRetryNum, long retryCycle, boolean fallbackFEEnable, boolean mockEnable, boolean failNotifyEnable){
		this.passRate=passRate;
		this.maxRetryNum=maxRetryNum;
		this.retryCycle=retryCycle;
		this.fallbackFEEnable=fallbackFEEnable;
		this.mockEnable=mockEnable;
		this.failNotifyEnable=failNotifyEnable;
	}

	public double getPassRate() {
		return passRate;
	}

	public void setPassRate(double passRate) {
		this.passRate = passRate;
	}

	public int getMaxRetryNum() {
		return maxRetryNum;
	}

	public void setMaxRetryNum(int maxRetryNum) {
		this.maxRetryNum = maxRetryNum;
	}

	public long getRetryCycle() {
		return retryCycle;
	}

	public void setRetryCycle(long retryCycle) {
		this.retryCycle = retryCycle;
	}

	public boolean isMockEnable() {
		return mockEnable;
	}

	public void setMockEnable(boolean mockEnable) {
		this.mockEnable = mockEnable;
	}

	public boolean isFallbackFEEnable() {
		return fallbackFEEnable;
	}

	public void setFallbackFEEnable(boolean fallbackFEEnable) {
		this.fallbackFEEnable = fallbackFEEnable;
	}

	public boolean isFailNotifyEnable() {
		return failNotifyEnable;
	}

	public void setFailNotifyEnable(boolean failNotifyEnable) {
		this.failNotifyEnable = failNotifyEnable;
	}

	public String toString() {
		return "ModuleConf [passRate=" + passRate + ", maxRetryNum="
				+ maxRetryNum + ", retryCycle=" + retryCycle + ", mockEnable="
				+ mockEnable + ", fallbackFEEnable=" + fallbackFEEnable
				+ ", failNotifyEnable=" + failNotifyEnable + "]";
	}

}
